﻿using Dapper.DBContext;
using Guoc.BigMall.Application;
using Guoc.BigMall.Application.DTO;
using Guoc.BigMall.Application.Search;
using Guoc.BigMall.Application.ViewObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Guoc.BigMall.Admin.Controllers
{
    public class MemberController : Controller
    {
        IContextFacade _context;
        IDBContext _db;
        IMemberFacade _memberFacade;
        IDistributeMemberFacade _distributeMemberFacade;

        public MemberController(IContextFacade context, IDBContext db, IMemberFacade memberFacade, IDistributeMemberFacade distributeMemberFacade)
        {
            this._context = context;
            this._db = db;
            this._memberFacade = memberFacade;
            this._distributeMemberFacade = distributeMemberFacade;

        }
        // GET: Member
        public ActionResult Index()
        {
            return View();
        }
        public JsonResult LoadData(Pager page, SearchMember search)
        {
            var rows = _memberFacade.GetList(page, search);
            return Json(new { success = true, data = rows, total = page.Total });
        }

        public JsonResult Create(MemberModel model)
        {
            _memberFacade.Create(model);
            return Json(new { success = true });
        }
        public JsonResult Edit(MemberModel model)
        {
            _memberFacade.Update(model);
            return Json(new { success = true });
        }

        //public JsonResult Remove(string ids)
        //{
        //    _memberFacade.Delete(ids);
        //    return Json(new { success = true });
        //}

        public JsonResult AddTopMember(int memberId)
        {
            _distributeMemberFacade.AddTopMember(memberId);
            return Json(new { success = true });
        }
    }
}